require 'digest/md5'
require 'json'
require 'pp'
require 'test/unit'

spec_dir = File.expand_path("..", __FILE__)
lib_dir = File.expand_path("../lib", spec_dir)

$LOAD_PATH.unshift(lib_dir)
$LOAD_PATH.uniq!

# https://gist.github.com/146844
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
class Hash
  def deep_diff(b)
    a = self
    (a.keys | b.keys).inject({}) do |diff, k|
      if a[k] != b[k]
        if a[k].respond_to?(:deep_diff) && b[k].respond_to?(:deep_diff)
          diff[k] = a[k].deep_diff(b[k])
        else
          diff[k] = [a[k], b[k]]
        end
      end
      diff
    end
  end
end

class SpouleTest < Test::Unit::TestCase
  def assert_diff_json(data, obj)
    expected = JSON.parse(data)
    actual = JSON.parse("{" + obj.to_json + "}")

    diff = expected.deep_diff(actual)
    assert_equal({}, diff)
  end
end

